package com.taotao.portal.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.common.util.JsonUtils;
import com.taotao.content.service.ContentService;
import com.taotao.pojo.TbContent;
import com.taotao.portal.pojo.AD1Node;

/**
 * 显示首页
 * @author Administrator
 *
 */
@Controller
public class PageController {
	@Autowired
	private ContentService contentService;
	@Value("${AD1_WIDTH}")
	private String AD1_WIDTH;
	
	@Value("${AD1_WIDTH_B}")
	private String AD1_WIDTH_B;
	
	@Value("${AD1_HEIGHT}")
	private String AD1_HEIGHT;
	
	@Value("${AD1_HEIGHT_B}")
	private String AD1_HEIGHT_B;
	
	@RequestMapping("/index")
	public String showIndex(Model model) {
		
		List<TbContent> contentList = contentService.getContentList();
		
		List<AD1Node> nodes = new ArrayList<AD1Node>();
		
		for (TbContent item : contentList) {
			AD1Node node = new AD1Node();
			node.setAlt(item.getSubTitle());
			node.setHref(item.getUrl());
			node.setSrc(item.getPic());
			node.setSrcB(item.getPic2());
			node.setHeight(AD1_HEIGHT);
			node.setHeightB(AD1_HEIGHT_B);
			node.setWidth(AD1_WIDTH);
			node.setWidthB(AD1_WIDTH_B);
			
			nodes.add(node);
		}
		model.addAttribute("ad1",JsonUtils.objectToJson(nodes));
		return "index";
	}
}
